import {createApp} from 'vue'
import App from './App.vue'
// import './index.css'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router'
import request from './utils/request'
import {createPinia} from 'pinia'
import { start, close } from './utils/nprogress';
import {userName} from "./config";
import {ElNotification } from "element-plus";


// 全局路由守卫
router.beforeEach((to,from,next) => {
    start()
    if (to.path === '/login') {
        next()
    } else if (!localStorage.getItem(userName)) {
        ElNotification.warning('请先认证')
        next({ path: '/login' })
    } else {
        next()
    }
})
router.afterEach(() => {
    close()
})

const pinia = createPinia()
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.config.globalProperties.request = request
app.use(ElementPlus, {
    locale: zhCn,
})
app.use(pinia)
app.use(router)
app.mount('#app')
